<?php

/**
 * Bill Class
 *
 */
class Bill {

    var $id = 0;
    var $name = '';
    var $amount = 0;
    var $due_date = null;
    var $color = '#000'; // Black
    var $days_till_due = 0;

    function __construct($biller_id, $name, $amount, $due_date) {

        $this->id = $biller_id;
        $this->name = $name;
        $this->amount = $amount;
        $this->due_date = $due_date;
        $this->days_till_due = $this->days_till_due($due_date);
        $this->color = $this->set_color($this->days_till_due);
    }

    /**
     * Finds how many days till due
     * 

     */
    public function days_till_due($date) {

        $today = new DateTime();

        $interval = $today->diff($date);

        return $interval->days;
    }

    /**
     * Returns the color based on number of days
     * 
     * @assert("0") == "#F00"
     * @assert("7") == "#F00"
     * @assert("8") == "#F93"
     * @assert("14") == "#F93"
     * @assert("15") == "#FF0"
     * @assert("28") == "#FF0"
     * @assert("29") == "#0F0"
     * @assert("250") == "#0F0"
     */
    public function set_color($days) {

        if ($days <= 7) {
            return '#F00'; // Red
        } else if ($days <= 14) {
            return '#F93'; // Orange
        } else if ($days <= 28) {
            return '#FF0'; // Yellow
        } else {
            return '#0F0'; // Green
        }
    }

}

/* End bill.php */
